package 二叉树;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

public class kthLargest {
    Queue<Integer> que;
    public int kthLargest(TreeNode root, int k) {
        que=new PriorityQueue<>(k, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        dfs(root);
        int min=Integer.MAX_VALUE;
        for(Integer x:que){
            if(x<min){
                min=x;
            }
        }
        return min;
    }
    public void dfs(TreeNode root){
        if(root==null) {
            return;
        }
        dfs(root.left);
        que.add(root.val);
        dfs(root.right);
    }

}
